/*
* $Id: Thread.cpp 323 2011-07-24 20:16:16Z volok-aleksej@yandex.ru $
*
* Copyright 2009-2011 by Volokitin Aleksey
* All rights reserved
*
*/
#include "Common/include.h"
#include "Thread.h"

CThread::CThread()
	: m_nId(0), m_handle(NULL){}
CThread::~CThread(){}

bool CThread::CreateThread(){
	m_handle = ::CreateThread(NULL, sizeof(CThread*),
		(LPTHREAD_START_ROUTINE)&CThread::FuncThread, this, 0, (LPDWORD)&m_nId);
	if(m_nId && m_handle)
		return true;
	return false;
}

int CThread::FuncThread(void* param){
	CThread* pThread = (CThread*)param;
	int result = pThread->ThreadFunc();
	pThread->m_nId = 0;
	pThread->m_handle = NULL;
	return result;
}

void CThread::StopThread(){
	if(m_handle && m_nId)
		Stop();
}

void CThread::ResumeThread(){
	if(m_handle && m_nId)
		Resume();
}

void CThread::PauseThread(){
	if(m_handle && m_nId)
		Pause();
}

bool CThread::IsStarted(){
	return m_handle && m_nId;
}
